import { Injectable } from '@nestjs/common'
import { CreateCompDto } from './dto/create-comp.dto'
import { UpdateCompDto } from './dto/update-comp.dto'
import { PrismaService } from 'src/prisma/prisma.service'

@Injectable()
export class CompService {
  constructor(private prisma: PrismaService) {}
  create(createCompDto: CreateCompDto) {
    return this.prisma.comp.create({ data: createCompDto })
  }

  async findAll(args: Record<string, any>) {
    const shortName = args.name || {}
    return await this.prisma.comp.findMany({
      where: {
        shortName,
      },
    })
  }

  findOne(id: number) {
    return this.prisma.comp.findFirst({ where: { id } })
  }

  update(id: number, updateCompDto: UpdateCompDto) {
    return this.prisma.comp.update({ where: { id }, data: updateCompDto })
  }

  remove(id: number) {
    return this.prisma.comp.delete({ where: { id } })
  }
}
